package com.xjtu.platform.user.admin.visit_arrange;

import com.xjtu.platform.common.CommonService;
import com.xjtu.platform.common.Result;
import com.xjtu.platform.common.TokenUtils;
import com.xjtu.platform.common.model.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @创建人 MBY381
 * @创建时间 2022/7/2 09:05
 * @描述 暂无
 */



@RestController
@RequestMapping("/admin")
public class AdminAPI {

    @Resource
    private CommonService commonService;

    @Resource
    private AdminService adminService;

    @RequestMapping(value = "/visit/getList",method = RequestMethod.POST)
    public Result getPage(@RequestHeader String Token,@RequestBody AdminDto adminDto){
        String adminId=TokenUtils.getUserInfo(Token,commonService).getUserId();
        adminDto.setUser_id(adminId);
        Map<String,Object> page = adminService.getInfo(adminDto);

        return Result.success(page);
    }


    @RequestMapping(value = "/getFreeConsultant",method = RequestMethod.GET)
    public Result getFreeConsultant(){
        try {
            List<User> data= adminService.getFreeConsultant();
            return Result.success("查询空闲教师成功",data);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail(Result.ERR_CODE_SYS,"系统错误！");
        }
    }

    @RequestMapping(value = "/arrange",method = RequestMethod.POST)
    public Result arrangeVisitForStudent(@RequestBody User visitor,@RequestParam("student") String student){
        System.out.println("path变量:"+student);
        System.out.println("选择的导师"+visitor.getUser_id());
        try {
            adminService.updateConsultant(visitor,student);
            return Result.success("已为学生: "+student+" 分配 "+visitor.getUser_id()+" 咨询师");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail(Result.ERR_CODE_SYS,"系统错误");
        }
    }

    @RequestMapping(value = "/informStudentOutOfVisitor",method = RequestMethod.POST)
    public Result informStudentOutOfVisitor(@RequestBody User user){
        try {
            System.out.println("/informStudentOutOfVisitor::::::"+user.getUser_id());
            adminService.informStudentOutOfVisitor(user.getUser_id());
            return Result.success("已通知 "+user.getUser_id()+" 学生情况");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail(Result.ERR_CODE_SYS,"系统错误！");
        }
    }

}
